package system

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"go-admin/app/admin/models"
	orm "go-admin/common/global"
	"go-admin/tools"
	"go-admin/tools/app"
)

/**
* @Description:
* @Author: yuweizhu
* @Date: 2020/11/5 1:43 上午
**/
func QueryAccount(c *gin.Context) {
	var data models.TAccount
	var id int
	var err error

	if value := c.Param("id"); value != "" {
		id, err = tools.StringToInt(value)
	}
	data.UserId = int64(id)
	result, err := data.Get()
	tools.HasError(err, "", -1)
	app.OK(c, result, "")
}

func ModifyAccount(c *gin.Context) {
	var data models.SysUser
	err := c.BindWith(&data, binding.JSON)
	tools.HasError(err, "非法数据格式", 500)

	id, err := data.Update(orm.GetDb(), data.UserId)
	tools.HasError(err, "修改失败", 500)
	app.OK(c, id, "修改成功")
}

func CreateAccount(userId int) {
	var data models.TAccount

	data.UserId = int64(userId)
	err := data.Insert()
	tools.HasError(err, "添加失败", 500)
}
